﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace WeForms
{
    public partial class WeTabForm : Form
    {
        private bool _hastContainer;
        public WeTabForm()
        {
            InitializeComponent();
            base.AutoSize = true;
            AutoSizeMode = AutoSizeMode.GrowAndShrink;
            MaximizeBox = false;
            MinimizeBox = false;
            StartPosition = FormStartPosition.Manual;
            Location = new Point(0, 0);

        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            if (_hastContainer) return;
           
        }

        protected override void OnControlAdded(ControlEventArgs e)
        {
            base.OnControlAdded(e);
            if(e.Control is WeTabContainer)
            {
                if(_hastContainer)
                {
                    throw new InvalidOperationException("Only one WeTabContainer can be placed on a WeTabForm");
                }
                _hastContainer = true;
            }
        }

        protected override void OnControlRemoved(ControlEventArgs e)
        {
            base.OnControlRemoved(e);
            if (e.Control is WeTabContainer)
            {
                _hastContainer = false;
            }
        }
    }
}
